/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Assignment.BLO;

import Assignment.DAO.Book_OrderDAO;
import Assignment.DTO.Book_OrderDTO;
import Assignment.DTO.Book_OrderListDTO;
import Assignment.DTO.OrderListDTO;
import Assignment.Util.ConnectionUtil;
import java.io.File;
import java.sql.Connection;
import java.util.ArrayList;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

/**
 *
 * @author dieptn
 */
public class Book_OrderBLO {

    private Connection con;

    public String getAllBookOrders() {
        String path = "";
        try {
            con = ConnectionUtil.getConnection();
            ArrayList<Book_OrderDTO> list = Book_OrderDAO.search(con, null);
            path = ConnectionUtil.getBookOrderFilePath();
            Book_OrderListDTO listBO = new Book_OrderListDTO();
            for (int i = 0; i < list.size(); i++) {
                listBO.getBookOrderList().add(list.get(i));
            }
            JAXBContext ctx = JAXBContext.newInstance(Book_OrderListDTO.class);
            Marshaller mar = ctx.createMarshaller();
            mar.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
            mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            mar.marshal(listBO, new File(path));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return path;
    }
}
